package com.qili.service.supervisor.impl;

import com.qili.base.mapper.BaseMapper;
import com.qili.base.service.impl.BaseServiceImpl;
import com.qili.entity.supervisor.ProjectLeader;
import com.qili.entity.supervisor.dto.ProjectLeaderDTO;
import com.qili.mapper.supervisor.ProjectLeaderMapper;
import com.qili.service.supervisor.ProjectLeaderService;
import com.qili.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lenovo on 2020/11/2.
 */
@Service
public class ProjectLeaderServiceImpl extends BaseServiceImpl<ProjectLeader,String> implements ProjectLeaderService {

    @Autowired
    ProjectLeaderMapper projectLeaderMapper;
    @Override
    public BaseMapper<ProjectLeader, String> getMappser() {
        return projectLeaderMapper;

    }

    @Override
    public int insert(ProjectLeader projectLeader) {
        return projectLeaderMapper.insert(projectLeader);
    }
    /**
    * @Author:zhaoyongke
    * @Description:
    * @param dto
    * @Date:11:16 2020/12/11
    */
    public List<ProjectLeaderDTO> selectProjectLeaderList(ProjectLeaderDTO dto){
        List<ProjectLeaderDTO>  leaderList= projectLeaderMapper.selectProjectLeaderList(dto);
        return leaderList;
    }
    /**
    * @Author:Zhangshuo
    * @Description:
    * @param ids
    * @Date:20:52 2020-12-11
    */
    @Override
    public int deleteByProjectIds(String[] ids) {
        return projectLeaderMapper.deleteByProjectIds(ids);
    }

    /**
     * @Author:zhaoyongke
     * @Description:是否是业主单位  根据当前用户判断
     * @param projectId
     * @Date:17:23 2021/1/6
     */
    public Boolean isYzUser(String projectId){
        String userId= CommonUtil.getUserId();
        ProjectLeader projectLeader = new ProjectLeader();
        projectLeader.setSupervisorProjectId(projectId);
        projectLeader.setProjectLeader(userId);
        int  count= projectLeaderMapper.selectCount(projectLeader);
        if(count>0){
            return true;
        }else{
            return false;
        }
    }

    /**
     * @Author:zhaoyongke
     * @Description:是否是业主单位  根据当前用户判断
     * @param projectId
     * @Date:17:23 2021/1/6
     */
    public Boolean isYzUserJlApp(String projectId,String userId){
        ProjectLeader projectLeader = new ProjectLeader();
        projectLeader.setSupervisorProjectId(projectId);
        projectLeader.setProjectLeader(userId);
        int  count= projectLeaderMapper.selectCount(projectLeader);
        if(count>0){
            return true;
        }else{
            return false;
        }
    }
}
